package com.tianshuo.main;

import com.tianshuo.config.AppConfig;
import com.tianshuo.model.Person;
import com.tianshuo.model.User;
import com.tianshuo.model.X;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @ClassName : AnnotationApplicationContextTest
 * @Description : 注解配置spring启动类
 * @Author : tianshuo
 * @Date: 2020-08-20 11:24
 */
public class AnnotationApplicationContextTest {

	public static void main(String[] args) {

		AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(AppConfig.class);
		System.out.println(applicationContext.getBean(User.class));

		//使用的@Component 注解 配置的bean 使用的是ScannedGenericBeanDefinition
		System.out.println(applicationContext.getBeanDefinition("user").getClass());

		System.out.println(applicationContext.getBean("user"));
		//spring.xml方式配置的bean，使用的是默认的GenericBeanDefinition
		Person person = applicationContext.getBean(Person.class);
		System.out.println(applicationContext.getBeanDefinition("person").getClass());
		//使用配置@Configuration注解配置的配置类，使用的是AnnotationGenericBeanDefinition
		System.out.println(applicationContext.getBeanDefinition("appConfig").getClass());
		//如果使用@Bean注解配置， 使用的ConfigurationClassBeanDefinitionReader$ConfigurationClassBeanDefinition  继承 RootBeanDefinition 实现了 AnnotatedBeanDefinition
		System.out.println(applicationContext.getBeanDefinition("bdObject").getClass());


		System.out.println(applicationContext.getBean(X.class));
		System.out.println(applicationContext.getBean(X.class));
		System.out.println(applicationContext.getBean(X.class));

		System.out.println(person);
	}
}

